<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('出资人LPA') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('出资人名称')" prop="lpName">
        <el-input
          v-model="queryParams.lpName"
          :placeholder="$t('出资人名称')"
          clearable
        />
      </el-form-item>
      <el-form-item :label="$t('业务经理')" prop="managerName">
        <el-input
          v-model="queryParams.managerName"
          :placeholder="$t('业务经理')"
          clearable
        />
      </el-form-item>
      <el-form-item :label="$t('基金简称')" prop="fundName">
        <el-input
          v-model="queryParams.fundName"
          :placeholder="$t('基金简称')"
          clearable
        />
      </el-form-item>
      <el-form-item :label="$t('条款类型')" prop="clauseTypeLabel">
        <el-input
          v-model="queryParams.clauseTypeLabel"
          :placeholder="$t('条款类型')"
          clearable
        />
      </el-form-item>
      <el-form-item :label="$t('提醒人')" prop="userName">
        <el-input
          v-model="queryParams.userName"
          :placeholder="$t('提醒人')"
          clearable
        />
      </el-form-item>
      <el-form-item :label="$t('提醒时间')" prop="remindTime">
        <DatePicker v-model="queryParams.remindTime" value-format="yyyy-MM-dd hh:mm:ss" :placeholder="$t('提醒时间')" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="fundLpaTermsList"
      tooltip-effect="darkTable"
      :span-method="objectSpanMethod"
      border
      class="noneHoverBg"
    >
      <el-table-column :label="$t('出资人名称')" align="center" prop="lpName" fixed="left" show-overflow-tooltip width="180">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/fund/lpBase/lpBaseHome',query:{lpId:scope.row.lpId}}"
            class="link_a"
          >{{ scope.row.lpName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('业务经理')" align="center" prop="managerName" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ scope.row.managerName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金简称')" align="center" prop="fundName" show-overflow-tooltip width="180">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/fund/fundBasehome',query:{id:scope.row.fundId}}"
            class="link_a"
          >{{ scope.row.fundName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('条款类型')" align="center" prop="clauseTypeLabel" width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <span class="link-type" @click="viewLpaForm(scope.row)">{{ scope.row.clauseTypeLabel }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('提醒人')" align="center" prop="userName" width="180" show-overflow-tooltip>
        <template slot="header" slot-scope="{}">
          <span>{{ $t('提醒人') }}</span>
          <el-tooltip :content="$t('提醒人中已包含默认提醒人')" placement="top">
            <i class="el-icon-question" />
          </el-tooltip>
        </template>
        <template #default="scope">
          <span>{{ scope.row.userName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('提醒时间')" align="center" prop="remindTime" width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.remindTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('条款内容')" align="center" prop="clauseContent" min-width="160" show-overflow-tooltip>
        <template #default="scope">
          {{ scope.row.clauseContent }}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 关键条款对话框 -->
    <el-dialog :title="title" :visible.sync="dealTermsOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealContractTermsForm ref="dealContractTermsForm" />
    </el-dialog>
    <!-- 添加或修改出资人信息对话框 -->
    <el-dialog :title="title" :visible.sync="investFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundInvestorForm ref="fundInvestorForm" />
    </el-dialog>
    <!-- hetong -->
    <el-dialog :visible.sync="infoOpen" :title="$t('流程详情')" custom-class="dialogForm" style=" text-align: left;" :close-on-click-modal="false" :lock-scroll="false">
      <ProcessInfoForm ref="processInfoForm" />
    </el-dialog>
    <el-dialog :visible.sync="formOpen" :title="$t('LPA条款')" custom-class="dialogForm" style=" text-align: left;" :close-on-click-modal="false" :lock-scroll="false">
      <fundInvestorLpaForm ref="fundInvestorLpaForm" />
    </el-dialog>
  </div>
</template>

<script>
import dealContractTermsForm from '@/views/deal/terms/dealTermsForm.vue'
import ProcessInfoForm from '@/views/act/process/processInfoForm'
import { findFundLpaTermsList } from '@/api/fund/investorLpa/fundInvestorLpa'
import fundInvestorForm from '@/views/fund/investor/fundInvestorForm.vue'
import fundInvestorLpaForm from '@/views/fund/investorLpa/fundInvestorLpaForm.vue'
export default {
  components: {
    fundInvestorForm,
    dealContractTermsForm,
    ProcessInfoForm,
    fundInvestorLpaForm
  },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 遮罩层
          infoOpen: false,
          investFormOpen: false,
          formOpen: false,
          // 总条数
          total: 0,
          // 项目关键条款表格数据
          fundLpaTermsList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          dealTermsOpen: false,
          // 条款类型字典
          typeOptions: [],
            // 查询参数
            queryParams: {
                lpName: undefined,
                managerName: undefined,
                fundName: undefined,
                name: undefined,
                typeName: undefined,
                userName: undefined,
                clauseTypeLabel: undefined,
                remindTime: undefined,
                isTriggerName: undefined,
                isTrigger: undefined,
                pageNum: 1,
                pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          },
          rowIndex: '-1',
          OrderIndexArr: [],
          hoverOrderArr: []
      }
  },
  computed: {
  },
  created() {
      this.getList()
      this.getDicts('lpa_type').then(response => {
        this.typeOptions = response.data
      })
  },
  methods: {
    /** 查询项目关键条款列表 */
    getList() {
        this.loading = true
        findFundLpaTermsList(this.queryParams).then(response => {
            this.fundLpaTermsList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 表单重置
    reset() {
        this.form = {
            dealName: undefined,
            remindUserId: undefined,
            formDealId: undefined,
            nickName: undefined,
            contractActId: undefined,
            associatedContract: undefined,
            managerName: undefined,
            name: undefined,
            type: undefined,
            typeName: undefined,
            remark: undefined,
            remindTime: undefined,
            isTrigger: undefined,
            isTriggerName: undefined,
            triggerTime: undefined,
            updateBy: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.queryParams.isTrigger = undefined
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 修改按钮操作 */
    viewFundInvestorForm(row) {
      this.investFormOpen = true
      this.title = this.$t(this.$t('出资人信息'))
      this.$nextTick(() => {
        const data = {
          id: row.fundInvestorId
        }
        // 调用form页面的 init 方法初始化数据
        this.$refs.fundInvestorForm.init(data)
      })
    },
    /** 查看条款详情表单数据 */
    viewLpaForm(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.fundInvestorLpaForm.init(row)
      })
    },
    objectSpanMethod({ rowIndex, columnIndex }) {
      if (columnIndex === 0 || columnIndex === 1) {
        const spanArr = this.rowspan()
        for (let i = 0; i < spanArr.length; i++) {
          const _row = spanArr[rowIndex]
          return {
            rowspan: _row,
            colspan: 1
          }
        }
      }
    },
    rowspan() {
      // 二维数组，用于存放单元格合并规则
      const spanArr = []
      // 用于存储相同项的开始index
      let position = 0
      this.fundLpaTermsList.forEach((item, index) => {
        if (index === 0) {
          spanArr.push(1)
          position = 0
        } else {
          if (this.fundLpaTermsList[index].lpName === this.fundLpaTermsList[index - 1].lpName &&
            this.fundLpaTermsList[index].managerName === this.fundLpaTermsList[index - 1].managerName
          ) {
            spanArr[position] += 1 // 有相同项
            spanArr.push(0) // 名称相同后往数组里面加一项0
          } else {
            spanArr.push(1) // 同列的前后两行单元格不相同
            position = index
          }
        }
      })
      return spanArr
    }
  }
}
</script>
